package xyz.liuyuhe.StudySpring.ch5.limited;

import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class LimitedClassPathXmlApplicationContext extends ClassPathXmlApplicationContext{
    private List<ConfigurableApplicationContext> accessibleFactories;

    public LimitedClassPathXmlApplicationContext(String... configLocations) throws BeansException {
        super(configLocations);
    }
    
    public LimitedClassPathXmlApplicationContext(String[] configLocations, ApplicationContext parent)
            throws BeansException {
        super(configLocations, parent);
    }

    public LimitedClassPathXmlApplicationContext(List<ConfigurableApplicationContext> accessibleFactories,
            String... configLocations) {
        super((ApplicationContext)null);
        this.accessibleFactories = accessibleFactories;
        setConfigLocations(configLocations);
        refresh();
    }

    @Override
    protected DefaultListableBeanFactory createBeanFactory() {
        ExtListableBeanFactory bf = new ExtListableBeanFactory(getInternalParentBeanFactory());
        bf.setAccessibleFactories(accessibleFactories);
        return bf;
    }
}
